<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<th:block th:include="include :: jasny-bootstrap-css" />
<th:block th:include="include :: bootstrap-fileinput-css" />
<th:block th:include="include :: select2-css" />
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-companyManage-add">
			<div class="form-group">
				<label class="col-sm-3 control-label">公司名称：</label>
				<div class="col-sm-8">
					<input id="companyName" name="companyName" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">公司LOGO：</label>
				<div class="col-sm-5">
					<div class="fileinput fileinput-new" data-provides="fileinput">
						<div class="fileinput-preview thumbnail" data-trigger="fileinput" style="width: 200px; height: 120px;">
							<img id="companyLogoimg">
						</div>
						<div>
							<span class="btn btn-white btn-file"><span class="fileinput-new">选择公司LOGO</span><span class="fileinput-exists">更改</span><input type="file" id="img"></span>
							<a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
							<span style="width: 200px; height: 120px; color: red">请选择1M以内图片</span>
						</div>
					</div>
					<input id="companyLogo" name="companyLogo" type="hidden"/>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">行政区域</label>
				<div class="col-sm-8">
					<select class="form-control" id="regionId" name="regionId">
						<option th:each="region : ${regionList}" th:text="${region.regionTitle}" th:value="${region.regionId}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control" type="text">
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
	<th:block th:include="include :: jasny-bootstrap-js" />
	<th:block th:include="include :: bootstrap-fileinput-js" />
	<th:block th:include="include :: select2-js" />
    <script type="text/javascript">
		var prefix = ctx + "business/companyManage"
		$("#form-companyManage-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});

		$(function(){
            $('#img').on('change.bs.fileinput', function (e) {
                var img = e.currentTarget.files[0];
                var formData = new FormData();
                formData.append("file", img);
                $.ajax({
                    url: ctx + "business/attachment/upload",
                    data: formData,
                    type: "post",
                    processData: false,
                    contentType: false,
                    success: function(result) {
                        $("#companyLogoimg").attr("src",result.url);
                        $("#companyLogo").val(result.url);
                    }
                });
            });
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-companyManage-add').serialize());
	        }
	    }
	</script>
</body>
</html>
